package controllers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.Account_balance;

import com.et.mvc.JsonView;

/**
 * @author wzzz	
 * 学员账户余额
 *
 */
public class Account_balanceController extends ApplicationController {



	/**
	 * 返回全部功能
	 */
	public JsonView getAccount_balance(int rows, int page) throws Exception {
		String cond = "1=1";
		List<Object> tmpArgs = new ArrayList<Object>();
		Object[] args = tmpArgs.toArray();
		long total = Account_balance.count(Account_balance.class, cond, args); // 查询总数
		List<Account_balance> account_balances = Account_balance.findAll(Account_balance.class,cond, args,"id", rows, (page - 1) * rows); // 查询的一页资料

		// 构造JSON用的数据结构并返回JSON视图
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("total", total);
		result.put("rows", account_balances);
		return new JsonView(result);
	}

	public JsonView getCollect_record(int id) throws Exception {
		Account_balance account_balance = Account_balance.find(Account_balance.class, id);
		return new JsonView(account_balance);
	}

	/**
	 * 保存新建功能
	 */
	public JsonView save(Account_balance Account_balance) throws Exception {
		Account_balance.save();
		JsonView view = new JsonView("success:true");
		view.setContentType("text/html;charset=utf-8");
		return view;
	}

	/**
	 * 保存修改的功能
	 */
	public JsonView update(int id) throws Exception {
		Account_balance account_balance = Account_balance.find(Account_balance.class, id);
		updateModel(account_balance);
		account_balance.save();
		JsonView view = new JsonView("success:true");
		view.setContentType("text/html;charset=utf-8");
		return view;
	}

	/**
	 * 删除指定的功能
	 */
	public JsonView destroy(int id) throws Exception {
		Account_balance account_balance = Account_balance.find(Account_balance.class, id);
		account_balance.destroy();
		JsonView view = new JsonView("success:true");
		view.setContentType("text/html;charset=utf-8");
		return view;
	}



}
